package com.wholesmart.common.security.crypto;

import java.util.UUID;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 默认盐密码生成器
 * 
 * @author dyw
 * @date 2019年12月16日
 */
public class SaltGeneraterImpl implements SaltGenerater {
	protected Logger logger = LoggerFactory.getLogger(getClass());

	public SaltGeneraterImpl() {
		super();
		logger.info("默认盐密码生成器启用");
	}

	private static String MIDDLE_LINE = "-";

	private static String BLANK = "";

	@Override
	public String generater(int num) {
		return process(num);
	}

	/**
	 * 生成指定位数不带"-"的UUID
	 * 
	 * @param num
	 * @return
	 */
	private static String process(int num) {
		String uuid = UUID.randomUUID().toString();
		String uuid_without_line = uuid.replaceAll(MIDDLE_LINE, BLANK);
		return uuid_without_line.substring(0, num);
	}
}
